﻿
<%
const MAX_SIZE = 10 '单位MB
const NF_PAGE_SIZE = 10 '每页显示10个文件

if not userRightObj.canManage then
    message("您没有设置权限")
end if

call createDataFolders

dim NET_FOLDER,  folder, parentFolder,  path, realPath, used_size
NET_FOLDER = MISSLOG_ROOT & "/data/" & blogObj.blogId & "/netfolder" 

function checkPath(path)
	if instr(ucase(path), ucase(Server.mapPath(NET_FOLDER)))=1 then
		checkPath = true
	else
		checkPath = false
	end if

end function


function initFolder()
	dim fso
	set fso = createobject("Scripting.FileSystemObject")
	
	path = NET_FOLDER
	realPath = Server.mapPath(path)
	
	if not fso.folderExists(realPath) then
		fso.createFolder(realPath)
	end if
	
	folder=request.queryString("folder")
	
	if right(folder, 1) = "/" then
		folder = left(folder, len(folder) -1 )
	end if
	
	path = NET_FOLDER & folder
	realPath = Server.mapPath(path) 
	
	if not checkPath(realPath) then
		folder=""
		path = NET_FOLDER
		realPath = Server.mapPath(NET_FOLDER)
	end if
	
	if not fso.folderExists(realPath) then
	'	fso.createFolder(realPath)
		message("文件夹不存在")
	end if
	
	dim nf
	set nf=fso.getfolder(realPath)
	used_size = nf.size
	set nf=nothing
	
	if instrrev(folder,"/") > 1 then
		parentFolder = mid(folder, 1, instrrev(folder,"/")-1)
	end if
	set fso = nothing
	
	session("net_folder_path") = path
end function

call initFolder()



function getFileType(string)
    getFileType=lcase(right(string,len(string)-instrrev(string,".")))
end function

function getFileIcon(string)
    dim filetype, fso, path
    filetype=getFileType(string)
    set fso = CreateObject("Scripting.FileSystemObject")
    path = Server.MapPath("images/"& filetype & ".gif")
    if fso.FileExists(path) then
        getFileIcon = filetype & ".gif"
    else
        getFileIcon = "unknow.gif"
    end if
    set fso = nothing
end function

function createFolder(name)
	dim fso, realPath
	realPath = Server.MapPath(path & "/" & name)
	if checkPath(realPath) then
		set fso = CreateObject("Scripting.FileSystemObject")
		If fso.FolderExists(realPath)=false Then
		   fso.CreateFolder(realPath)
		end if
		set fso=nothing
	else
		message("创建文件夹失败")
	end if
end function

function delFolder(name)
	dim fso, realPath
	realPath = Server.MapPath(path & "/" & name)
	if checkPath(realPath) then
		set fso = CreateObject("Scripting.FileSystemObject")
		if fso.FolderExists(realPath)=true then
			fso.DeleteFolder (realPath)
		else
			message("文件夹" & name &"不存在")
		end if
		set fso=nothing
	else
		message("删除文件夹失败")
	end if
end function

function delFile(name)
	dim fso, realPath, file
	realPath = Server.MapPath(path & "/" & name)
	if checkPath(realPath) then
		set fso = CreateObject("Scripting.FileSystemObject")
		if fso.FileExists(realPath)=true then
			set file=fso.getfile(realPath)
			file.delete
			set file = nothing
		else
			message("文件" & name &"不存在")
		end if
		set fso=nothing
	else
		message("删除文件失败")
	end if
end function



function moveFolder(oldfolder, newfolder)
	dim fso, realPath, realPath2, file
	realPath = Server.MapPath(path & "/" & oldfolder)
	realPath2 = Server.MapPath(path & "/" & newfolder)
	if checkPath(realPath) and checkPath(realPath2) then
		set fso = CreateObject("Scripting.FileSystemObject")
		if fso.FolderExists(realPath)=true then
			call fso.MoveFolder(realPath, realPath2)
		else
			message("文件夹" & oldfolder &"不存在")
		end if
		set fso=nothing
	else
		message("更改文件名失败")
	end if
end function


function moveFile(oldname, newname)
	
	dim ftype, fso, realPath, realPath2, file
	ftype=getFileType(newname)
	if ftype="asp" or ftype="aspx" or ftype="inc"  or ftype="php"  or ftype="cgi"  or ftype="pl" then
		message("非法文件类型")
	end if
	realPath = Server.MapPath(path & "/" & oldname)
	realPath2 = Server.MapPath(path & "/" & newname)
	if checkPath(realPath) and checkPath(realPath2) then
		set fso = CreateObject("Scripting.FileSystemObject")
		if fso.FileExists(realPath)=true then
			set file=fso.getfile(realPath)
			file.move(realPath2)
			set file = nothing
		else
			message("文件" & oldname &"不存在")
		end if
		set fso=nothing
	else
		message("更改文件名失败")
	end if
end function
%>